var var_startDate=null;
var var_endDate=null;
jQuery(document).ready(function(){
	var_startDate=$("#startDate").val();
	var_endDate=$("#endDate").val();
	/*��ȡĬ����ʼ����ʱ��*/
//	$.ajax({
//		type: "POST",
//		url: rootPath + "/selfvisit.do?method=getDefaultDate",
//		dataType:"json",
//		async:false,
//		success: function(retJson){
//			jQuery("#startDate").val(retJson.lastWeek);
//			jQuery("#endDate").val(retJson.now);
//		}
//	});
//	$("#orgGrade").initUnitGrade({code:'org',name:'orgGrade',orgCode:$("#org_id").val(),isMult:false});
	/*�����Ӧ���ֶβ�ѯ�׷ü�¼*/
	jQuery("#search").click(function(){
		if($("#org_id").val()==''||$("#org_id").val()==null){
			alert("����������!");
			return;
		}
		var postData = getPostData();
		jQuery("#navgrid").jqGrid('setGridParam',{url:rootPath + '/selfvisit.do?method=queryOrgCount',postData:postData}).trigger("reloadGrid");
	});
	/**���ð�ť��ʽ*/
	$("input:button").button();
	/** �׷���ϢGrid */
	var lastsel;
	jQuery("#navgrid").jqGrid({
		url:rootPath + '',
		mtype: "post",
		datatype: "json",
		colNames:['���','�����','�����','��Ϣ��','չҵ','�շ�','��Ա','��ȫ','��ֵ','����','�ϼ�','��Ч��Ϣ��','�����Ϣ��','�Լ���Ч��Ϣռ��','��Ч��Ϣ��ռ��','�����','���ռ��'],
		colModel:[
		          {name:'id',index:'id',align:'center', width:35, editable:false},
		          {name:'managecom',index:'managecom', width:80, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'name',index:'name', width:200, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'sum_message',index:'sum_message', width:60, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'zhy_message',index:'zhy_message', width:40,editable:false,editoptions:{size:20},editrules:{required:true}},
		          {name:'sf_message',index:'sf_message', width:40,editable:false,editoptions:{size:20},editrules:{required:true}},
		          {name:'zey_message',index:'zey_message', width:40, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'bq_message',index:'bq_message', width:40, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'zez_message',index:'zez_message', width:40, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'other_message',index:'other_message', width:40, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'sum_message1',index:'sum_message1', width:40, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'unuse_message',index:'unuse_message', width:80, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'untruth_message',index:'untruth_message', width:80, editable:false,editoptions:{readonly:true,size:10}},
		          {name:'self_validate_p',index:'self_validate_p', width:90, editable:false},
		          {name:'check_validate_p',index:'check_validate_p', width:90, editable:false},
		          {name:'check_sum',index:'check_sum', width:55,editable:false},
		          {name:'check_truth_p',index:'check_truth_p',align:'left', width:70,editable:false}
		          ],
		          rowNum:25,          //Ĭ���Ǽ�����ʾ
		          multiselect: false,
		          rowList:[10,20,30], //������ʾ
		          pager: '#pagernav', //�����Ǹ�div
		          caption:"�׷�ά��",
		          jsonReader : {  
		        	  root: "rows",   // json�д��ʵ��ģ����ݵ����
		        	  page: "page",   // json�д�?ǰҳ������
		        	  total: "total", // json�д��ҳ����������
		        	  records: "records", // json�д���������������
		        	  repeatitems: false,  
		        	  id: "0" 
		          },
		          height: 'auto', //���߶� ԭʼֵ:300
		          width:  '925',   //����� ԭʼֵ: 900
		          shrinkToFit:false
	});
	$( "#navgrid" ).jqGrid( 'setGroupHeaders' , {
		useColSpanStyle :  true ,  // û�б�ͷ�����Ƿ����ͷ��λ�õĿյ�Ԫ��ϲ�
		groupHeaders : [ {
		startColumnName :  'zhy_message' ,  // ��ӦcolModel�е�name
		numberOfColumns : 7,  // ��Խ������
		titleText :  '��Ϣ'
		}]
		});
	/*�����������ͬ�����pngͼƬ��͸��������*/
	fixPNG('search_icon','/images/common/icon-2.png');
	fixPNG('search_icon1','/images/common/icon-2.png');
	fixPNG('user-reset-password','/images/group/user-reset-password-01.png');
	fixPNG('accountStateY','/images/setTrue.png');
	fixPNG('accountStateN','/images/setTrue.png');
	
	$("#accountStateY").mouseout(function(){
		fixPNG('accountStateY','/images/setTrue.png');
	});
	$("#accountStateN").mouseout(function(){
		fixPNG('accountStateN','/images/setTrue.png');
	});
	
	$("#accountStateY").click(function(){
		fixPNG('accountStateY','/images/setFalse.png');
		setTruth("0");
	});
	
	$("#accountStateN").click(function(){
		fixPNG('accountStateN','/images/setFalse.png');
		setTruth("1");
	});
	
	/*���ò�ѯ����*/
	jQuery("#reset").click(function(){
		$("#order input:text").attr("value","");
		$("#org_id").val(orgId);
		$("#startDate").val(var_startDate);
		$("#endDate").val(var_endDate);
	});
	/*����*/
	jQuery("#export").click(function(){
		var postData = getPostData();
		var url="/selfvisit.do?method=orgSta_toExcel&orgCode="+$.trim($("#org_id").val())+
        "&upBranch="+ $.trim($("#orgGrade").val())+
        "&startDate="+ $.trim($("#startDate").val())+
        "&endDate="+ $.trim($("#endDate").val());
		window.location.href=url;
	});
	//�ؼ���ʽ�Լ���Ϊ����
	$(".datepicker").datepicker(
	{
		changeMonth: true,
		changeYear: true,
		showAnim: "drop",
		dateFormat: "yy-mm-dd"
	});
	$(":input:text").addClass("text ui-widget-content ui-corner-all");
	$("select").addClass("ui-widget-content ui-corner-all");
	$("input:button").add(":button").button();
});
function getPostData(){
	var org_id = $.trim($("#org_id").val());
	var grade = $.trim($("#orgGrade").val());
	var startDate = $.trim($("#startDate").val());
	var endDate = $.trim($("#endDate").val());
	
	// (4)��õ�ǰpostDataѡ���ֵ  
	var postData = $("#navgrid").jqGrid("getGridParam", "postData");  
    
	postData.orgCode = org_id;
	postData.upBranch = grade;
	postData.startDate = startDate;
	postData.endDate = endDate;
	return postData;
}

